package com.lx.gulimall.seckill.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Controller;

import java.io.IOException;

/**
 * @author lixun Email:lx3027@126.com
 * @create 2021-07-22 17:50
 */
@Controller
public class MyRedissonConfig {
    /**
     * 所有对Redisson的使用都是通过RedissonClient对象
     * @return
     * @throws IOException
     */
    @Bean(destroyMethod = "shutdown")
    public RedissonClient redisson() throws IOException {
        // 创建配置
        Config config = new Config();
        //config.useClusterServers()
        //        .addNodeAddress("127.0.0.1:7004", "127.0.0.1:7001");
        // 单节点
        config.useSingleServer().setAddress("redis://192.168.1.101:6379");
        // 2.根据config创建出RedissonClient实例
        RedissonClient redissonClient = Redisson.create(config);
        return redissonClient;
    }

}
